<template>
  <div class="content">
    <div class="scroll-view-box">
      <div class="user-title-box">{{ jdysArrData.node_name }}</div>
      <template v-for="(item, index) in jdysArrData.criteria_list">
        <div class="cont-node-box" :key="index">
          <p class="title-box">
            <span>{{ index + 1 }}.</span>
            {{ item.node_name }}
          </p>
          <template v-if="item.content_type == 1">
            <div class="content">{{ item.content || '未提交任何信息' }}</div>
          </template>
          <template v-if="item.content_type == 2">
            <div class="file-box-img-box flex ac content" v-if="item.node_files.length">
              <template v-for="(file, idx) in item.node_files">
                <div class="file-box-img" :key="idx">
                  <el-tooltip class="item" effect="dark" :content="file.file_name" placement="top">
                    <img @click="$fileViewHandle(file)" class="img" :src="$fileImgFunc(file)" />
                  </el-tooltip>
                </div>
              </template>
            </div>
            <div class="content" v-else>未提交任何信息</div>
          </template>
          <el-radio-group v-model="item.audit_state" size="small">
            <el-radio :label="2">通过</el-radio>
            <el-radio :label="3">拒绝</el-radio>
          </el-radio-group>
          <div class="textarea">
            <!--  v-if="item.audit_state == 3" -->
            <el-input placeholder="审批意见" :rows="4" v-model="item.reason_rejection" type="textarea"></el-input>
          </div>
        </div>
      </template>
      <span slot="footer">
        <el-button type="primary" @click="jdysshSubmit()" :disabled="diaLoading" :loading="diaLoading">提交</el-button>
        <el-button @click="jdysshCancel()">关闭</el-button>
      </span>
    </div>
  </div>
</template>
<script>
import engineeringApi from "@/api/engineeringApi";
import { getUserInfo } from "@/utils/auth";

export default {
  name: "jdysshCom",
  data() {
    return {
      diaLoading: false,
      jdysArrData: "",
    };
  },
  watch: {},
  computed: {},
  mounted() {
    this.project_id = this.$route.query.id;
    this.getProjectNodeDetails();
  },
  methods: {
    // 节点验收审核
    jdysshCancel() {
      this.$goBackTab(this);
    },
    // 提交审核
    jdysshSubmit() {
      let jdysArrData = this.jdysArrData;
      let userInfo = getUserInfo();
      console.log(jdysArrData.criteria_list, "参数", jdysArrData)
      for (let i = 0; i < jdysArrData.criteria_list.length; i++) {
        if (jdysArrData.criteria_list[i].audit_state == 3 && !jdysArrData.criteria_list[i].reason_rejection) {
          this.$message({
            type: 'warning',
            message: '请输入审批意见'
          })
          return;
        }
      }
      let data_arr = [];
      jdysArrData.criteria_list.forEach(item => {
        data_arr.push({
          id: item.id,
          audit_state: item.audit_state,
          reason_rejection: item.reason_rejection || ''//item.audit_state == 3 ? item.reason_rejection : ''
        })
      })
      // 工程监理 初审
      this.qualityAcceptanceAudit({
        data_arr,
        project_id: jdysArrData.project_id,
        node_id: jdysArrData.id,
        node_data: jdysArrData
      })
    },
    // 初审
    qualityAcceptanceAudit(obj) {
      console.log(obj, "----")
      this.diaLoading = true;
      engineeringApi.qualityAcceptanceAudit(obj).then(res => {
        console.log(res, "节点验收初审")
        this.diaLoading = false;
        if (res.code == 200) {
          this.jdysshCancel();
        }
        this.$message({
          type: res.code == 200 ? 'success' : 'warning',
          message: res.message
        })
      })
    },
    // 节点提交详情
    getProjectNodeDetails() {
      this.logList = [];
      engineeringApi
        .getProjectNodeDetails({
          node_id: this.$route.query.id,
        })
        .then((res) => {
          console.log(res, "节点提交详情");
          if (res.code == 200) {
            res.data.criteria_list.forEach(item => {
              item.audit_state = 2;
              item.reason_rejection = '';
            })
            this.jdysArrData = res.data;
          }
        })
        .catch((err) => {
          this.logLoaidng = false;
        });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/dialogPageCss.scss";
</style>